package com.zcl.servlet;
import com.alibaba.fastjson.JSON;
import com.zcl.entity.R;
import com.zcl.entity.dept;
import com.zcl.service.*;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import com.zcl.service.*;

import java.io.IOException;
import java.util.List;

@WebServlet("/dept")
public class deptServlet extends HttpServlet {
    private deptService deptService;

    @Override
    public void init() throws ServletException {
        deptService=new deptServiceImpl();
    }

    @Override
    public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException {
     //设置响应字符集编码
     res.setContentType("text/html;charset=utf8");
     //查询所有部门列表
        List<dept> dept=deptService.findALL();
        //转化为字符串
        final R r = R.ok().put("list", dept);
        //打印输出
        res.getWriter().println(JSON.toJSONString(r));
        res.getWriter().flush();
    }
};


